package com.homework;

import sun.text.normalizer.UTF16;

import java.io.*;

public class homework1 {
    public static void main(String[] args) throws IOException {
        String filepath = "E:\\Java\\java_code\\mytemp";
        File file = new File(filepath);
        if (!file.exists()) {
            file.mkdir();
            System.out.println("目录创建成功");
        }
        String filepath1 = "E:\\Java\\java_code\\mytemp\\hello.txt";
//        File file1 = new File(filepath1);
//            BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(filepath1));
//
//            bufferedWriter.write("hello,world~，中文");
//            System.out.println("    输入成功");
//            bufferedWriter.close();

        //若将文件格式改成ANSI，则会乱码，用一下格式获取
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(filepath1), "gbk"));//ANSI国标格式
        String line = "";
        int linecount = 0;
        while ((line = bufferedReader.readLine()) != null) {
            System.out.print(linecount + "   ");
            System.out.println(line);
            linecount++;
        }
        bufferedReader.close();
    }
}
